"""
jackson.views

Views to define the Jackson web UI.

@author: rk
"""

from jackson import debug

debug.pre_import(__name__)

from django.template.loader import render_to_string
from django.http import HttpResponse

from jackson.chord import db
from jackson.cdn.core import get_state

debug.post_import(__name__)


def check_alive(request):
    return HttpResponse(render_to_string('base.html',
                                     {'sidebar':'welcome to jackson',
                                      'centered_title': 'sup y\'all'
                                    })) 
def sup(request):
    """ print some info about the server
    """
    t = ["me: " + db.get_me().ip +":"+str(db.get_me().port ),
        "(my hash): " + db.get_me().key[:4],
        "pred: " + db.get_predecessor().ip + ":" + str(db.get_predecessor().port),
        "succ: " + db.get_predecessor().ip + ":" + str(db.get_successor().port),
        "keys: " + str(get_state('low'))[:4] + " to " + str(get_state('high'))[:4]]
    
    return HttpResponse(render_to_string('base.html',
                                           {'centered_title': 'machine overview',
                                            'content':t,
                                            'content_is_list':True}))
